﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PublSystem
{
    public partial class Publication : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            uint pageId;

            try
            {
                pageId = uint.Parse(Request.QueryString["id"]);
            }
            catch
            {
                pageId = 1;
            }

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
            {
                SqlDataAdapter cmd = new SqlDataAdapter("SELECT * FROM PublicationsInfo.Publications WHERE publicationId = " + pageId + ";", conn);
                conn.Open();
                DataSet ds = new DataSet();
                cmd.Fill(ds);
                
                publ.DataSource = ds;
                publ.DataBind();


                SqlDataAdapter cmdKw = new SqlDataAdapter(@"SELECT * FROM PublicationsInfo.Keywords
                                                        , PublicationsInfo.KeywordsPublications , PublicationsInfo.Publications WHERE PublicationsInfo.KeywordsPublications.keywordId = PublicationsInfo.Keywords.keywordId 
                                                        AND PublicationsInfo.Publications.publicationId = PublicationsInfo.KeywordsPublications.publicationId
                                                        AND PublicationsInfo.Publications.publicationId="+pageId, conn);
                DataSet kds = new DataSet();
                cmdKw.Fill(kds);
                Keywords.DataSource = kds;
                Keywords.DataBind();

                SqlDataAdapter cmdA = new SqlDataAdapter(@"SELECT * FROM PublicationsInfo.Authors
                                                        , PublicationsInfo.AuthorsPublications , PublicationsInfo.Publications WHERE PublicationsInfo.AuthorsPublications.authorId = PublicationsInfo.Authors.id 
                                                        AND PublicationsInfo.Publications.publicationId = PublicationsInfo.AuthorsPublications.publicationId
                                                        AND PublicationsInfo.Publications.publicationId=" + pageId, conn);
                DataSet ads = new DataSet();
                cmdA.Fill(ads);
                Authors.DataSource = ads;
                Authors.DataBind();
            }
        }
    }
}